<template>
  <div>
    <el-table
      :data="goodslist"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="id" label="商品编号" width="100"></el-table-column>
      <el-table-column prop="goodsname" label="商品名称"></el-table-column>
      <el-table-column prop="price" label="商品价格"></el-table-column>
      <el-table-column prop="market_price" label="市场价格"></el-table-column>
      <el-table-column prop="img" label="图片">
        <template slot-scope="scope">
          <img :src="$pre+scope.row.img" alt />
        </template>
      </el-table-column>
      <el-table-column prop="isnew" label="是否新品">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1">是</el-button>
          <el-button type="info" v-else>否</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="ishot" label="是否热卖">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1">是</el-button>
          <el-button type="info" v-else>否</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1">启用</el-button>
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="change(scope.row.id)">修改</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :page-size="3" :total="goodscount" class="fr" @current-change="currentChange"></el-pagination>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import {
  reqgoodsadd,
  reqgoodsdit,
  reqgoodsdelete
} from "../../../request/api.js";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      info: "goods/info",
      goodslist: "goods/goodslist",
      goodscount: "goods/goodscount",
      page: "goods/page",
    })
  },
  methods: {
    ...mapActions({
      reqgoodslist: "goods/goodslist",
      reqgoodsinfo: "goods/goodsinfo",
      reqgoodscount: "goods/goodscount",
      reqpage: "goods/reqpage",
      changepage: "goods/changepage"
    }),
    currentChange(page) {
      this.changepage(page)
    },
    change(id) {
      this.info.isadd = false;
      this.info.isshow = true;
      this.reqgoodsinfo({ id: id });
    },
    del(id) {
      reqgoodsdelete({ id: id });
      this.reqgoodslist();
    }
  },
  mounted() {
    this.reqgoodslist();
    this.reqgoodscount();
  }
};
</script>

<style scoped>
img {
  width: 100px;
  height: 100px;
}
</style>